<template>
    <div class="appointment-Three" v-if="bookInfoData">
        <div class="header-box">
            <div class="header-left">
                <div class="back" v-if="is_back">
                    <i class="el-icon-arrow-left" @click="backFun"></i>
                </div>
                <div class="title">预约详情</div>
            </div>
            <div class="header-right">
                <el-button size="mini" @click="orintFun">打印</el-button>
            </div>
        </div>
        <div class="status-box">
            <div class="status-val">
                <span>预约状态：{{ bookInfoData.status_txt }}</span>
            </div>
            <div
                class="status-doc"
                :class="bookInfoData.status == 2 ? 'doc-avitve' : ''"
            >
                <span>{{
                    bookInfoData.top_notes
                        ? bookInfoData.top_notes
                        : bookInfoData.isremark_txt
                        ? "评价状态：" + bookInfoData.isremark_txt
                        : ""
                }}</span>
            </div>
        </div>
        <div class="info-data-box comm-list">
            <div class="order-info-box">
                <div class="order-num-tiem">
                    <span class="num">单号：{{ bookInfoData.no }}</span>
                    <span class="tiem">{{ bookInfoData.atime_txt }}</span>
                </div>
                <div
                    class="order-uer"
                    v-if="bookInfoData.customer_info.customerid"
                >
                    <div class="img-box">
                        <img
                            :src="
                                bookInfoData.customer_info &&
                                bookInfoData.customer_info.avatar
                                    ? bookInfoData.customer_info.avatar
                                    : img_buf
                            "
                        />
                    </div>
                    <div class="name-phone">
                        <div class="name">
                            <span>{{ bookInfoData.customer_info.name }}</span>
                        </div>
                        <div class="phone">
                            <span>{{
                                bookInfoData.customer_info.cellphone
                            }}</span>
                        </div>
                    </div>
                </div>
                <div class="remark-info" v-if="bookInfoData.remark_info">
                    <div class="remark">
                        <el-rate
                            v-model="bookInfoData.remark_info.score"
                            disabled
                        >
                        </el-rate>
                        <span class="score-txt">{{
                            bookInfoData.remark_info.score_txt
                        }}</span>
                    </div>
                    <div class="tiem" v-if="bookInfoData.remark_info.txt">
                        <span>评语：{{ bookInfoData.remark_info.txt }}</span>
                    </div>
                    <div class="tiem">
                        <span>{{ bookInfoData.remark_info.time_txt }}</span>
                    </div>
                </div>
                <div class="order-txt" v-if="bookInfoData.txt">
                    <span>备注：{{ bookInfoData.txt }}</span>
                </div>
            </div>
            <div class="order-info-box" v-if="bookInfoData.sign_img">
                <div class="order-num-tiem">
                    <span class="num">客户签名</span>
                </div>
                <div class="order-uer">
                    <img class="order-sing-img" :src="bookInfoData.sign_img" alt="">
                </div>
            </div>
            <div class="store-info-box">
                <div class="store-num-tiem">
                    <span class="num">门店：{{ bookInfoData.shop_name }}</span>
                </div>
                <div class="store-uer">
                    <div class="store-uer-left">
                        <div class="img-box">
                            <img
                                :src="
                                    bookInfoData.staff_info.avatar
                                        ? bookInfoData.staff_info.avatar
                                        : require('../../static/images/default_circle_head.png')
                                "
                            />
                        </div>
                        <div class="name-phone">
                            <div class="name">
                                <span>{{ bookInfoData.staff_info.name }}</span>
                            </div>
                            <div class="phone">
                                <span
                                    >{{
                                        parseFloat(
                                            bookInfoData.staff_info.remark_score
                                        )
                                    }}分</span
                                >
                            </div>
                        </div>
                    </div>
                    <div
                        class="store-uer-right"
                        v-if="bookInfoData.staff_info.position_title"
                    >
                        <el-tag type="success" effect="plain">{{
                            bookInfoData.staff_info.position_title
                        }}</el-tag>
                    </div>
                </div>
                <div class="store-txt">
                    <span>预约时间：{{ bookInfoData.h_from_txt }}</span>
                    <span>结束时间：{{ bookInfoData.h_to_txt }}</span>
                </div>
            </div>
            <div class="good-info-box">
                <div
                    class="good-info-row"
                    v-for="(item, index) in bookInfoData.pro_list"
                    :key="index"
                >
                    <div class="img-box">
                        <img :src="item.img_small ? item.img_small : img_buf" />
                    </div>
                    <div class="good-info">
                        <div class="good-name">
                            <span>{{ item.title }}</span>
                        </div>
                        <div class="good-doc">
                            <span>{{ item.txt_title }}</span>
                        </div>
                        <div class="good-summary">
                            <span>次数：{{ item.serv_qty }}次</span
                            ><span
                                >单价：{{ parseFloat(item.serv_price) }}元</span
                            ><span>剩余：{{ item.serv_left }}次</span
                            ><span>共：{{ item.serv_qty_total }}次</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="but-box" v-if="bookInfoData.acts">
            <div
                class="but zho"
                v-if="bookInfoData.acts.cancel"
                @click="operationBook('1')"
            >
                <!-- 取消预约 -->
                <span>{{ bookInfoData.acts.cancel.title }}</span>
            </div>

            <div
                class="but zho"
                v-if="bookInfoData.acts.edit"
                @click="modificationFun"
            >
                <!-- 修改预约 -->
                <span>{{ bookInfoData.acts.edit.title }}</span>
            </div>

            <div
                class="but sut"
                v-if="bookInfoData.acts.tock2"
                @click="confirmArrival"
            >
                <!-- 确认消费 -->
                <span>{{ bookInfoData.acts.tock2.title }}</span>
            </div>

            <div
                class="but avt"
                v-if="bookInfoData.acts.tock"
                @click="operationBook('2')"
            >
                <!-- 确认预约 -->
                <span>{{ bookInfoData.acts.tock.title }}</span>
            </div>
        </div>
    </div>
</template>

<script>
import staticConst from "../../js/const/StaticConst.js";
import config from "@/js/conf/Config.js";

export default {
    name: "appointmentThree",
    props: ["is_back"],
    data() {
        return {
            img_buf: staticConst.GOOD_IMG,
            bookInfoData: null,
            book_id: "",
        };
    },
    methods: {
        // 确认消费
        confirmArrival () {
            this.$confirm('是否确认消费？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.bookActAjax("tock2");

            }).catch(() => {});
        },
        async bookActAjax (act) {
            let url = config.YY_YUYUE_BOOK_STATUS_ACT;
            let param = {
                bookid: this.book_id,
                act: act,
            }
            let res = await this.$api({ url: url, data: param });
            if (res.status == 1) {
                this.$msg({ title: res.msg });
                setTimeout(() => {
                    this.getBookDetail();
                    this.upDataList();
                }, 500);
            }
        },  
        //返回
        backFun() {
            this.$emit("backFun");
        },
        // 修改预约单
        modificationFun() {
            const data = {
                bookid: this.book_id,
            };
            this.$emit("modificationFun", data);
        },
        //更新列表数据
        upDataList() {
            this.$emit("upDataList");
        },
        // 初始
        initData(id) {
            this.book_id = id;
            this.getBookDetail();
        },

        // 取消/确认预约
        async operationBook(type) {
            let url = config.YY_YUYUE_BOOK_STATUS_ACT;
            let param = {
                bookid: this.book_id,
                act: type == 1 ? "cancel" : "tock",
            };
            let res = await this.$api({ url: url, data: param });
            if (res.status == 1) {
                this.$msg({ title: res.msg });
                setTimeout(() => {
                    this.getBookDetail();
                    this.upDataList();
                }, 500);
            }
        },
        // 打印
        orintFun() {
            this.$confirm("确定要打印该预约详情吗?", "打印", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
            })
                .then(() => {
                    let url = config.COMM_PRINT_DO;
                    let param = {
                        type: "yy",
                        odid: this.book_id,
                        type12: "",
                    };
                    this.$api({ url: url, data: param });
                })
                .catch(() => {});
        },
        // 获取详情
        async getBookDetail() {
            let url = config.YY_YUYUE_BOOK_DETAIL;
            let param = {
                bookid: this.book_id,
            };
            let res = await this.$api({ url: url, data: param });
            if (res.status == 1 && res.data) {
                this.bookInfoData = res.data;
                if (this.bookInfoData.remark_info) {
                    this.bookInfoData.remark_info.score = Number(
                        this.bookInfoData.remark_info.score
                    );
                }
            }
        },
    },
};
</script>

<style lang="scss" scoped>
.appointment-Three {
    height: 100vh;
    width: 100%; //calc(100% - 418px);
    background-color: #fff;
    position: relative;
    .header-box {
        height: 50px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-bottom: 1px #e8dcdc solid;
        padding: 0 10px;
        padding-right: 10px;
        display: flex;
        .header-left {
            display: flex;
            .back {
                font-size: 20px;
                margin-right: 10px;
                cursor: pointer;
            }
            .title {
                font-size: 18px;
            }
        }
    }
    .but-box {
        position: absolute;
        left: 0;
        bottom: 0;
        height: 60px;
        width: 100%;
        border-top: 1px #e8dcdc solid;
        background: #fff;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        .but {
            height: 100%;
            padding: 0 20px;
            font-size: 16px;
            display: flex;
            align-items: center;
            cursor: pointer;
            &.zho {
                border-left: 1px #ede6e6 solid;
                &:hover {
                    background: #f7f7f8;
                }
            }
            &.sut {
                background: #67C23A;
                color: #fff;
                &:hover {
                    background: #7fcf57;
                }
            }
            &.avt {
                background: #3388ff;
                color: #fff;
                &:hover {
                    background: #5498f7;
                }
            }
        }
    }
    .status-box {
        height: 40px;
        background: #f2f2f2;
        display: flex;
        align-items: center;
        font-size: 14px;
        padding: 0 20px;
        .status-val {
            span {
                padding-right: 10px;
                border-right: 1px #d2d2d2 solid;
            }
        }
        .status-doc {
            margin-left: 10px;
            &.doc-avitve {
                color: #fa4848;
            }
        }
    }

    .info-data-box {
        height: calc(100% - 180px);
        padding: 0 10px;
        overflow: auto;
        font-size: 14px;
        margin-top: 10px;
        .order-info-box {
            border: 1px #e8dcdc solid;
            border-radius: 5px;
            padding: 10px;
            margin-bottom: 20px;
            .order-sing-img {
                width: 300px;
                max-height: 210px;
            }
            .order-num-tiem {
                display: flex;
                justify-content: space-between;
                align-items: center;
                height: 30px;
                .tiem {
                    color: #9f9f9f;
                }
            }
            .order-uer {
                margin-top: 10px;
                display: flex;
                align-items: center;
                padding-top: 20px;
                padding-bottom: 20px;
                border-top: 1px #e8dcdc solid;

                .img-box {
                    width: 80px;
                    height: 80px;
                    border-radius: 50%;
                    overflow: hidden;
                    margin-right: 20px;
                    img {
                        width: 100%;
                        height: 100%;
                        object-fit: cover;
                    }
                }
                .name-phone {
                    .name {
                        margin-bottom: 5px;
                    }
                }
            }
            .remark-info {
                padding-top: 10px;
                border-top: 1px #e8dcdc solid;
                .remark {
                    display: flex;
                    align-items: center;
                    .score-txt {
                        margin-left: 5px;
                    }
                }
                .tiem {
                    font-size: 12px;
                    color: #9f9f9f;
                }
            }
            .order-txt {
                margin-top: 10px;
                padding-top: 10px;
                border-top: 1px #e8dcdc solid;
            }
        }
        .store-info-box {
            border: 1px #e8dcdc solid;
            border-radius: 5px;
            padding: 10px;
            margin-bottom: 20px;
            .store-num-tiem {
                display: flex;
                justify-content: space-between;
                height: 40px;
                border-bottom: 1px #e8dcdc solid;

                .tiem {
                    color: #9f9f9f;
                }
            }
            .store-uer {
                margin-top: 20px;
                display: flex;
                align-items: center;
                justify-content: space-between;
                padding-bottom: 20px;
                margin-bottom: 10px;
                border-bottom: 1px #e8dcdc solid;
                .store-uer-left {
                    display: flex;
                    align-items: center;
                    .img-box {
                        width: 80px;
                        height: 80px;
                        border-radius: 5px;
                        overflow: hidden;
                        margin-right: 20px;
                        img {
                            width: 100%;
                            height: 100%;
                            object-fit: cover;
                        }
                    }
                    .name-phone {
                        .name {
                            margin-bottom: 5px;
                        }
                    }
                }
            }
            .store-txt {
                display: flex;
                font-size: 12px;
                span {
                    margin-right: 20px;
                }
            }
        }
        .good-info-box {
            border: 1px #e8dcdc solid;
            border-radius: 5px;
            padding: 10px;
            .good-info-row {
                display: flex;
                margin-bottom: 10px;
                &:last-child {
                    margin: 0;
                }
                .img-box {
                    width: 80px;
                    height: 80px;
                    border-radius: 5px;
                    overflow: hidden;
                    margin-right: 20px;
                    img {
                        width: 100%;
                        height: 100%;
                        object-fit: cover;
                    }
                }
                .good-info {
                    width: calc(100% - 100px);
                    div {
                        margin-bottom: 5px;
                    }
                    .good-doc {
                        font-size: 12px;
                        color: #aaaaaa;
                    }
                    .good-summary {
                        font-size: 12px;
                        span {
                            margin-right: 10px;
                        }
                    }
                }
            }
        }
    }
}
</style>